explicit operator bool() const noexcept;
true if the object is callable.false otherwise (the object is an empty function).1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// function::operator bool example
#include <iostream> // std::cout
#include <functional> // std::function, std::plus
int main () {
std::function<int(int,int)> foo,bar;
foo = std::plus<int>();
foo.swap(bar);
std::cout << "foo is " << (foo ? "callable" : "not callable") << ".\n";
std::cout << "bar is " << (bar ? "callable" : "not callable") << ".\n";
return 0;
}
foo is not callable. bar is callable.